#!/bin/bash

# 北京国庆出游规划助手 - 一键启动脚本

echo "========================================="
echo "  北京国庆出游规划助手"
echo "========================================="
echo ""

# 检查是否安装了g++
if ! command -v g++ &> /dev/null; then
    echo "错误：未找到g++编译器，请先安装："
    echo "  Ubuntu/Debian: sudo apt-get install g++"
    echo "  CentOS/RHEL: sudo yum install gcc-c++"
    echo "  macOS: xcode-select --install"
    exit 1
fi

# 进入后端目录
cd backend

echo "正在编译后端服务器..."
if make; then
    echo "✅ 编译成功！"
    echo ""
    echo "启动选项："
    echo "1. 启动服务器"
    echo "2. 仅编译，不启动"
    echo "3. 退出"
    
    read -p "请选择 (1-3): " choice
    
    case $choice in
        1)
            echo ""
            echo "正在启动服务器..."
            echo "服务器将在 http://localhost:8080 启动"
            echo ""
            echo "使用说明："
            echo "- 打开浏览器访问 http://localhost:8080"
            echo "- 或打开 frontend/index.html 查看前端页面"
            echo ""
            ./travel_server
            ;;
        2)
            echo "编译完成，程序已生成：backend/travel_server"
            ;;
        3)
            echo "已退出"
            ;;
        *)
            echo "无效选择，已退出"
            ;;
    esac
else
    echo "❌ 编译失败！"
    echo "请检查错误信息并修复后重试"
    exit 1
fi
